﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Zeta.Game.Internals.Actors;

namespace KadalaSpree.XCore
{
    /// <summary>
    /// Base class that exposes additional events
    /// </summary>
    public class XModule
    {
        public string Name { get; set; }

        internal static X.Logger Logger { get; set; }
        public static XFlow Flow = new XFlow();

        internal XPlugin Plugin { get; set; }
        internal DateTime LastPulse { get; set; }        

        public virtual void DebouncedPulse() { }
        public virtual void Pulse() { }
        public virtual void OnEnabled() { }
        public virtual void OnDisabled() { }
        public virtual void OnInitialize() { }
        public virtual void OnShutdown() { }
        public virtual void OnStart() { }
        public virtual void OnStop() { }
        public virtual void OnGameChanged() { }

        /// <summary>
        /// Time between pulses in Milliseconds
        /// </summary>
        public int DebounceInterval { get; set; }

        public XModule()
        {
            DebounceInterval = X.Settings.PulseInterval;
        }

        internal void BaseInitialize()
        {
            Logger = new X.Logger(this);
        }

        public List<XModule> Modules 
        {
            get { return Plugin.Modules.Modules; }
        }

        public XModule GetModuleByType<T>()
        {
            return Modules.FirstOrDefault(m => m.GetType() == typeof(T));
        }

        public List<XModule> GetModulesByType<T>()
        {
            return Modules.Where(m => m.GetType() == typeof(T)).ToList();
        }


    }
}
